using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace hxSec.StaticPage
{
    public class ChartQueue
    {
        public ChartQueue() { }
        private int count=0;        //队列中节点的个数
        private Node nOutNode=null; //输出端
        private Node oInNode=null;  //输入端

        //// <summary> 
        /// 队列中节点总数 
        /// </summary> 
        public int Count
        {
            get { return count; }
        }

        /// <summary> 
        /// 入队列 
        /// </summary> 
        /// <param name="o">进队对象</param> 
        public void Push(object o)
        {
            Node nextNode = new Node(o);
            if (oInNode != null)
            {
                oInNode.NodeNext = nextNode;
            }

            oInNode = nextNode;

            if (nOutNode == null)
            {
                nOutNode = oInNode;
            }
            count++;
        }

        /// <summary> 
        /// 出队 
        /// </summary> 
        /// <returns>队列当前节点的值</returns> 
        public object Pop()
        {
            if (nOutNode == null)
            {
                throw new Exception("队列空!");
            }
            else
            {
                object objValue = nOutNode.Value;
                nOutNode = nOutNode.NodeNext;
                count--;
                return objValue;
            }
        }
    }

    #region 队列节点
    /// <summary>
    /// 队列节点
    /// </summary>
    public class Node
    {
        private Node _node;
        private object _value;

        public Node(object v)
        {
            this._value = v;
            this._node = null;
        }

        public Node NodeNext
        {
            get { return _node; }
            set { _node = value; }
        }
        public object Value
        {
            get { return _value; }
        }

    }
    #endregion 
}
